---
title: Process third-party retention
summary: Fetches claims due for retention, archives each batch in OnBase, and marks the Imaging API retention records processed.
status: draft
owner: Documents
last_reviewed: 2026-10-22
operation_id: OP-OB3P-001
trigger: Execute lifecycle stage of a scheduled run
---

# Process third-party retention

This operation is the entire body of `ThirdPartyRetentionProcessor.Execute`. It retrieves the retention records due for the processing date, splits them into batches, sends each batch to OnBase, and marks the batch's records as processed in the Imaging API.

| Attribute | Value |
| --- | --- |
| Operation ID | OP-OB3P-001 |
| Lifecycle stage | Execute |
| Owner | `ThirdPartyRetentionProcessor.Execute` |
| Inputs | `Month`, `Day`, `Year` ([arguments](../arguments.md)); `processob3pretention.processbatchsize` |
| Outputs | Console log lines; exit code 0 or 5 |
| Business rules | [BR-OB3P-001](../business-rules.md#br-ob3p-001-processing-date-defaults-to-current-date), [BR-OB3P-002](../business-rules.md#br-ob3p-002-batch-size-from-environment-setting-with-default-of-100), [BR-OB3P-003](../business-rules.md#br-ob3p-003-eligibility-is-decided-by-the-imaging-api), [BR-OB3P-004](../business-rules.md#br-ob3p-004-batch-sent-to-onbase-as-a-placeholder-document), [BR-OB3P-005](../business-rules.md#br-ob3p-005-mark-processed-only-after-onbase-succeeds), [BR-OB3P-006](../business-rules.md#br-ob3p-006-zero-eligible-claims-is-a-successful-run), [BR-OB3P-007](../business-rules.md#br-ob3p-007-any-error-stops-the-run-without-rollback), [BR-OB3P-008](../business-rules.md#br-ob3p-008-audit-user-is-fixed) |

## Steps

1. Write `Processing Third Party retention document deletion.` to the log.
2. Call the Imaging API `GET` `toProcess` endpoint with the month, day, and year arguments, and log one line per claim: `SAIF Claim Num: <n> - Close Date: <d>`. See [BR-OB3P-001](../business-rules.md#br-ob3p-001-processing-date-defaults-to-current-date) and [BR-OB3P-003](../business-rules.md#br-ob3p-003-eligibility-is-decided-by-the-imaging-api).
   - Imaging API exceptions (`SAIF.API.Exceptions.*`) are caught by step 8 and end the run with exit code 5.
   - An unparseable response body is treated as an empty result by the HTTP client, which leads to step 3.*
3. If no claims were returned, write `No claims eligible for retention policy deletion.` and finish with exit code 0. See [BR-OB3P-006](../business-rules.md#br-ob3p-006-zero-eligible-claims-is-a-successful-run).
4. Read `processob3pretention.processbatchsize` from the Environment API. A positive integer is used; an empty, non-integer, or non-positive value yields 100. See [BR-OB3P-002](../business-rules.md#br-ob3p-002-batch-size-from-environment-setting-with-default-of-100).
   - A missing key throws `ApplicationException` (exit code 5).
5. Write `Processing n claims in b batch(es) of up to size.` and split the claims into consecutive batches.
6. For each batch, call `OnBaseService.ProcessRetention`, which invokes the SOAP `ArchiveDocument` operation with a placeholder text document keyed by the batch's claim numbers, then log `Claims sent to OnBase for Retention Processing.  OnBase Document ID: <id>`. See [BR-OB3P-004](../business-rules.md#br-ob3p-004-batch-sent-to-onbase-as-a-placeholder-document) and the [OBRetentionService client documentation](../../../clients/obretentionservice/index.md).
   - `FaultException`, `CommunicationException`, or `TimeoutException`* from OnBase is caught by step 8 (exit code 5).
7. Call the Imaging API `PUT` `processed/mark` endpoint with the batch's retention ids and the fixed audit user, then log `THRDPARTY_RETENTION records marked as processed.  ID List:` followed by the ids. See [BR-OB3P-005](../business-rules.md#br-ob3p-005-mark-processed-only-after-onbase-succeeds) and [BR-OB3P-008](../business-rules.md#br-ob3p-008-audit-user-is-fixed). Repeat steps 6 and 7 for the next batch.
   - A failure here leaves the batch archived in OnBase but not marked, so the next run may resubmit it.*
8. On any exception raised from step 2 onward, write `Error: <message>` to stderr and rethrow; remaining batches are not attempted and the run exits with code 5. See [BR-OB3P-007](../business-rules.md#br-ob3p-007-any-error-stops-the-run-without-rollback).
   - Step 1's log write executes before the `try` block; if it throws, the exception is not caught here and no `Error:` line is written.*

## Process flow

The diagram shows this operation's own steps, including the empty-result exit and the failure exit.

```mermaid
flowchart TD
    S["Log start message"] --> G["GET toProcess for month/day/year"]
    G --> Q{"Any claims?"}
    Q -- "No" --> N["Log no claims eligible"]
    N --> Z["Exit code 0"]
    Q -- "Yes" --> B["Read batch size (default 100)"]
    B --> P["Split claims into batches"]
    P --> L{"Next batch?"}
    L -- "No" --> Z
    L -- "Yes" --> O["OnBase ArchiveDocument"]
    O --> M["PUT processed/mark"]
    M --> L
    G -- "Exception" --> E["Write Error to stderr and rethrow"]
    B -- "Exception" --> E
    O -- "Exception" --> E
    M -- "Exception" --> E
    E --> X["Exit code 5"]
```

## Logging

Output goes through `IConsoleLogService` only: `Write` for progress (stdout) and `WriteError` for the `Error:` line (stderr). Claim numbers, close dates, and retention ids are written to the log, so captured output contains claim data.

## Error handling

`Execute` wraps the workflow in a single `try`/`catch (Exception)` that writes `Error: <message>` and rethrows with `throw ex;`, resetting the stack trace. The framework runner then reports the exception again and exits with code 5. There is no retry in the application; the Imaging HTTP client retries transient statuses internally.† No transaction spans the OnBase and Imaging calls.

> **Note:** Statements marked with `†` are derived from dependency library
> documentation via the Legends CLI. Statements marked with `*` were inferred
> from code structure or contextual evidence.

## Sources

- `ProcessOB3PRetention/ThirdPartyRetentionProcessor.cs`
- `ProcessOB3PRetention/Services/ImagingApiClient.cs`
- `ProcessOB3PRetention/Services/OnBaseService.cs`
- `ProcessOB3PRetention/ArgContainer.cs`
- `ProcessOB3PRetention/Contracts/ThirdPartyRetention.cs`
